layui.use(['jquery', 'layer', 'form', 'table', 'laydate'], function () {
    var $ = layui.jquery,
        layer = layui.layer,
        form = layui.form,
        table = layui.table,
        laydate = layui.laydate;

    laydate.render({
        elem: '#year',
        type: 'year',
        value: new Date()
    });

    $("#doSearch").click(function () {
        getData();
    });

    function getData() {
        var year = $("#year").val();
        if (year === "") {
            year = new Date().getFullYear();
        }

        $.post("/statistics/inpatientFinance", {year: year}, function (data) {
            var dom = document.getElementById("container");
            var myChart = echarts.init(dom);
            var app = {};
            option = null;
            option = {
                color: ['#3398DB'],
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'shadow'
                    }
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis: [
                    {
                        type: 'category',
                        data: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
                        axisTick:{
                            alignWithLabel: true
                        }
                    }
                ],
                yAxis: [
                    {
                        type: 'value'
                    }
                ],
                series: [
                    {
                        name:'',
                        type: 'bar',
                        barWidth: '60%',
                        data: data
                    }
                ]
            };

            if(option && typeof option === "object"){
                myChart.setOption(option,true);
            }
        });
    }

    getData();
});